function resequence(varargin)
% recompute the "sequence names" from the filenames in the Control sheet.
% this version strips off the leading 'pbm_' or the trailing '_pbm' from
% the filename before doing the sequence bit. It then calls make_sequence %
% and gets the sequence to put into the file
% 9 Feb 06 Paul B. Manis, Ph.D.
% Call: with arg, just prints the sequence we would make.
% without arg, DOES it an modifies the CONTROL structure...
global CONTROL

if(nargin > 0)
    testflag = 1;
else
    testflag = 0;
end;

nc = length(CONTROL); % do the whole list at once.
for i = 1:nc
    sf = i;
    fn = CONTROL(sf).filename;
    [p f e] = fileparts(fn); % strip stuff if it is present
    j = strfind(f, '_');
    if(~isempty(j))
        if(isletter(f(j-1))) % then we have a leading marker
            f = f(j+1:end);
        else
            f = f(1:j-1);
        end;
    end;
    seq = make_sequence(f, CONTROL(sf).recbeg);
    if(testflag)
        fprintf(1, 'file: %s   seq: %s\n', CONTROL(sf).filename, seq);
    else
        CONTROL(sf).seqname = seq; 
    end;
    
end;
